package de.devisnik.shifting.impl;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class PieceCanvas extends Canvas {

	public PieceCanvas(Composite parent, final Image image) {
		super(parent, SWT.NO_BACKGROUND );
		addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent e) {
				e.gc.setAntialias(SWT.ON);
				e.gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, getSize().x, getSize().y);
			}});
	}

	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		Image image = new Image(display, "images/Wasserlilien.jpg");
		new PieceCanvas(shell, image);
		shell.setSize(600, 400);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

}
